package com.ss.common.web;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ss.common.Console;

/**
 * 字符过滤器
 * 
 */
// 实现过滤器的方法 实现filter接口 重写doFilter方法
public class JspFilter implements Filter {

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        HttpServletRequest res=(HttpServletRequest) request;
        HttpServletResponse resp=(HttpServletResponse)response;
        Object obj=res.getSession().getAttribute(Console.SESSION_KEY_USER_INFO);
        String uri=res.getRequestURI();
        boolean valid=true;
        if(uri.contains("login.jsp")){
        	valid=false;
        }
        if(obj==null && valid){
        	resp.sendRedirect("login.jsp");
        }else{
        	chain.doFilter(request, response);
        }
    }

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		
	}
}
